package com.education.welco.controller;

import com.education.common.core.BaseController;
import com.education.common.utils.ApiReturnObject;
import com.education.welco.pojo.SAnsweringLike;
import com.education.welco.service.ISAnsweringLikeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 课堂答疑用户点赞 信息操作处理
 *
 * @author d
 * @date 2022-06-25
 */
@RestController
@RequestMapping("/sAnsweringLike")
public class SAnsweringLikeController extends BaseController {

    @Autowired
    private ISAnsweringLikeService sAnsweringLikeService;

    /**
     * 查询课堂答疑用户点赞列表
     */
    @GetMapping("/list")
    public ApiReturnObject list(SAnsweringLike sAnsweringLike, Integer pageNum, Integer pageSize) {
        if(pageNum != null && pageSize !=null ){
            PageHelper.startPage(pageNum,pageSize);
        }
        List<SAnsweringLike> list = sAnsweringLikeService.selectSAnsweringLikeList(sAnsweringLike);
        PageInfo pageInfo = new PageInfo<>(list);
        return new ApiReturnObject("200","查询成功",pageInfo);
    }


    /**
     * 新增保存课堂答疑用户点赞
     */
    @PostMapping("/add")
    public ApiReturnObject addSave(@RequestBody SAnsweringLike sAnsweringLike) {
        sAnsweringLikeService.insertSAnsweringLike(sAnsweringLike);
        return new ApiReturnObject("200","添加成功","");
    }


    /**
    * 详情课堂答疑用户点赞
    */
    @GetMapping("/selectOne")
    public ApiReturnObject selectOne(String id){
        SAnsweringLike result = sAnsweringLikeService.selectSAnsweringLikeById(id);
        return new ApiReturnObject("200","查询成功",result);
    }

    /**
     * 修改保存课堂答疑用户点赞
     */
    @PostMapping("/update")
    public ApiReturnObject editSave(@RequestBody SAnsweringLike sAnsweringLike) {
        sAnsweringLikeService.updateSAnsweringLike(sAnsweringLike);
        return new ApiReturnObject("200","修改成功","");
    }

    /**
     * 删除课堂答疑用户点赞
     */
    @PostMapping("/del")
    public ApiReturnObject remove(String ids) {
        sAnsweringLikeService.deleteSAnsweringLikeByIds(ids);
        return new ApiReturnObject("200","删除成功","");
    }
}